@layout("/common/_container.html"){
<div class="layui-card">
	<div class="layui-form layui-card-header layuiadmin-card-header-auto">
	  <div class="layui-form-item">
	    <div class="layui-inline">
	      	<label class="layui-form-label">名称</label>
			<div class="layui-input-block">
			  <input type="text" id="condition" id="condition" placeholder="差分账号/用户名" autocomplete="off" class="layui-input">
			</div>
	    </div>
	    <div class="layui-inline">
	      <button class="layui-btn layuiadmin-btn-useradmin" data-type="reload">
	        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
	      </button>
	    </div>
	  </div>
	</div>
  <div class="layui-card-body">
    <table class="layui-hidden" id="table" lay-filter="table"></table>
    
  	<script type="text/html" id="oper">
			{{#  if(d.applyState == 0){ }}
			@if(shiro.hasPermission("/rtk/review")){
  			<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="review" title="申请处理">申请处理</a>
			@}
			{{#  } else if(d.applyState == 1 && d.bindingState == 0) { }}
			@if(shiro.hasPermission("/rtk/binding")){
  			<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="binding" title="绑定标识">绑定标识</a>
			@} 
			{{#  } else if(d.applyState == 1 && d.bindingState == 1) { }}
			@if(shiro.hasPermission("/rtk/detail")){
  			<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail" title="设备详情">设备详情</a>
			@}
			@if(shiro.hasPermission("/rtk/update/eleFence")){
			<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="update" title="修改围栏">修改围栏</a>
			@}			
			{{#  } }}			
	</script>
  </div>
</div>

<script>
layui.config({
	base: Feng.ctxPath + "/static/layuiadmin/" //静态资源所在路径
}).extend({
	index: 'lib/index' //主入口模块
}).use(['index', 'layer','table', 'form'],function(){
	
	var $ = layui.$
  	,form = layui.form
  	,table = layui.table;
	var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 });
	table.render({
	    elem: '#table'
	    ,url: Feng.ctxPath + '/rtk/list'
	    ,cellMinWidth: 100
	    ,height: 'full-168' //设置高度
	    ,cols: [[
	    	{title: '差分账号', field: 'account'},
		    {title: '用户账号', field: 'userName'},
		    {title: '设备型号', field: 'machineModel'},
	        {title: '开始时间', field: 'startTime'},
	        {title: '购买时长', field: 'payTimeName'},
	        {title: '剩余时长', field: 'surplusTimeName'},
	        {title: '所属机构', field: 'organName'},
	        {title: '设备申请状态', field: 'applyStateName'},
	        {title: '绑定状态', field: 'bindingStateName'},
	       
	        {title: '操作',fixed: 'right', width:160, align:'center',fixed: 'right', toolbar: '#oper'}
	    ]]
	    ,page:true
	    ,loading:true
	    ,text: {
	        none: '暂无相关数据' 
	      }
	    ,done: function(res){
	    	layer.close(loadingIndex);
        }
	});
	
	//事件
	var active = {
		//加载
	   	reload: function(){
	       var condition = $('#condition').val();
	       var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 });
	       //执行表格重载
	       table.reload('table', {
	    	 height: 'full-168' //设置高度
	    	 ,where: {
	    		 condition: condition
	         }
	       ,page:true
	       ,done: function(res){
		    	layer.close(loadingIndex);
	        }
	      });
	    }
   };
  
   
   $('.layui-btn.layuiadmin-btn-useradmin').on('click', function(){
     var type = $(this).data('type');
     active[type] ? active[type].call(this) : '';
   });
	

 //监听工具条
   table.on('tool(table)', function(obj){
     var data = obj.data;
     if(obj.event === 'review'){
       var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 });
       layer.open({
         type: 2
         ,title: '申请处理'
         ,content: Feng.ctxPath + '/rtk/rtk_review/'+data.accountId
         ,area: ['937px', '507px']
         ,btn: ['确定', '取消']
         ,yes: function(index, layero){
           var iframeWindow = window['layui-layer-iframe'+ index]
           ,submitID = 'review-submit'
           ,submit = layero.find('iframe').contents().find('#'+ submitID);

           //监听提交
           iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
               var loading2 = layer.load(2);
             var field = data.field; //获取提交的字段
             var ajax = new $ax(Feng.ctxPath + "/rtk/review", function (data) {
                 Feng.success("处理成功!");
                 table.reload('table',{
               	  done: function(res){
          		    	layer.close(loadingIndex);
          	          }
                  }); //数据刷新
                 layer.close(loading2); //关闭弹层
                 layer.close(index); //关闭弹层
             }, function (data) {
                 Feng.error("处理失败!" + data.responseJSON.message + "!");
             },true);
             ajax.setData(field);
             ajax.start();
             
           });  
           
           submit.trigger('click');
         }
         ,btn2: function(index, layero){
    	   layer.close(loadingIndex);
         }
         ,cancel:function(index, layero){
    	   layer.close(loadingIndex);
         }
       });
     }else if(obj.event === 'binding'){
    	 var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 });
         layer.open({
           type: 2
           ,title: '绑定标识'
           ,content: Feng.ctxPath + '/rtk/rtk_binding/'+data.accountId
           ,area: ['530px', '340px']
           ,btn: ['确定', '取消']
           ,yes: function(index, layero){
             var iframeWindow = window['layui-layer-iframe'+ index]
             ,submitID = 'binding-submit'
             ,submit = layero.find('iframe').contents().find('#'+ submitID);

             //监听提交
             iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                 var loading2 = layer.load(2);
               var field = data.field; //获取提交的字段
               var ajax = new $ax(Feng.ctxPath + "/rtk/binding", function (data) {
                   Feng.success("处理成功!");
                   table.reload('table',{
                 	  done: function(res){
            		    	layer.close(loadingIndex);
            	          }
                    }); //数据刷新
                   layer.close(loading2); //关闭弹层
                   layer.close(index); //关闭弹层
               }, function (data) {
                   Feng.error("处理失败!" + data.responseJSON.message + "!");
               },true);
               ajax.setData(field);
               ajax.start();
               
             });  
             
             submit.trigger('click');
           }
           ,btn2: function(index, layero){
      	   layer.close(loadingIndex);
           }
           ,cancel:function(index, layero){
      	   layer.close(loadingIndex);
           }
         });
     }else if(obj.event === 'detail'){
    	 layer.open({
             type: 2
             ,title: '查看详情'
             ,content: Feng.ctxPath + '/rtk/detail/'+data.accountId
             ,area: ['720px', '390px']
             ,btn: ['取消']
             ,btn1: function(index, layero){
          	   layer.close(index); //关闭弹层
             }
           });
     }else if(obj.event === 'update'){
    	 var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 });
         layer.open({
           type: 2
           ,title: '修改围栏'
           ,content: Feng.ctxPath + '/rtk/update_eleFence/'+data.accountId
           ,area: ['720px', '415px']
           ,btn: ['确定', '取消']
           ,yes: function(index, layero){
             var iframeWindow = window['layui-layer-iframe'+ index]
             ,submitID = 'update-submit'
             ,submit = layero.find('iframe').contents().find('#'+ submitID);

             //监听提交
             iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                 var loading2 = layer.load(2);
               var field = data.field; //获取提交的字段
               var ajax = new $ax(Feng.ctxPath + "/rtk/update/eleFence", function (data) {
                   Feng.success("修改成功!");
                   table.reload('table',{
                 	  done: function(res){
            		    	layer.close(loadingIndex);
            	          }
                    }); //数据刷新
                   layer.close(loading2); //关闭弹层
                   layer.close(index); //关闭弹层
               }, function (data) {
                   Feng.error("修改失败!" + data.responseJSON.message + "!");
               },true);
               ajax.setData(field);
               ajax.start();
               
             });  
             submit.trigger('click');
           }
           ,btn2: function(index, layero){
      	   layer.close(loadingIndex);
           }
           ,cancel:function(index, layero){
      	   layer.close(loadingIndex);
           }
         });
     }
   });
});



   
</script>
@}
